package com.biz.hunter.dao;

import com.biz.hunter.db.entity.TbFile;
import com.biz.hunter.dbutil.BaseDAO;
import org.springframework.stereotype.Repository;

@Repository
public class TbFileDAO {

    private static String SQL_SAVE = "INSERT INTO `tb_file` (\n" +
            "\t`jobId`,\n" +
            "\t`personId`,\n" +
            "\t`docId`,\n" +
            "\t`original_name`,\n" +
            "\t`new_name`,\n" +
            "\t`file_type`,\n" +
            "\t`file_path`,\n" +
            "\t`convert_path`,\n" +
            "\t`relative_path`,\n" +
            "\t`creat_time`,\n" +
            "\t`update_time`,\n" +
            "\t`create_by`,\n" +
            "\t`update_by`,\n" +
            "\t`jsonParse`\n" +
            ")\n" +
            "VALUES\n" +
            "\t(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    private static String SQL_GET_DOCID = "select * from tb_file where docId = ?";

    private static String SQL_GET_BY_PERSONID = "select * from tb_file where personId = ? order by update_time desc limit 0,1";

    public TbFile getByDocId(String docId) {
        return BaseDAO.queryForObject(TbFile.class, SQL_GET_DOCID, docId);
    }

    public int save(TbFile tbFile) {
        return BaseDAO.execute(SQL_SAVE,tbFile.getJobId(),tbFile.getPersonId(),tbFile.getDocId(),tbFile.getOriginal_name(),tbFile.getNew_name(),
                tbFile.getFile_type(),tbFile.getFile_path(),tbFile.getConvert_path(),tbFile.getRelative_path(),tbFile.getCreate_time(),
                tbFile.getUpdate_time(),tbFile.getCreate_by(),tbFile.getUpdate_by(),tbFile.getJsonParse());
    }

    public TbFile getByPersonId(int personId) {
        return BaseDAO.queryForObject(TbFile.class, SQL_GET_BY_PERSONID, personId);
    }
}
